<?php

namespace app\webapi\controller;

use think\facade\Db;

class ApiCoupon extends ApiBaseController
{
    public $user_info = null;

    public function __construct()
    {
        $this->user_info = $this->checkToken();
        if (!preg_match('/^\d+$/', $this->user_info['id'])) {
            $this->result_error('用户id出错');
        }
    }

    /** 获取优惠券列表 */
    public function getCouponList()
    {
        $sql = "SELECT a.*,b.name,b.description,b.value,b.threshold,b.valid_day FROM sy_user_coupon a 
    INNER JOIN sy_coupon b ON a.cid=b.id 
    WHERE a.uid=? AND a.state>0 AND NOW()<a.time_valid 
    ORDER BY a.state DESC,a.update_time DESC ";
        $sql_result = Db::query($sql, [$this->user_info['id']]);
        $this->result_ok('ok', $sql_result);
    }
}